// pages/music/music.js
Page({
  data: {
    currentSong: null,
    isPlaying: false
  },

  onLoad(options) {
    const app = getApp();
    const playerManager = app.globalData.playerManager;
    
    if (playerManager) {
      this.setData({
        currentSong: playerManager.currentSong,
        isPlaying: playerManager.isPlaying
      });
      
      // 监听播放状态变化
      playerManager.watchPlayStatus(this.updatePlayStatus.bind(this));
    }
  },

  onUnload() {
    // 页面卸载时移除监听
    const app = getApp();
    const playerManager = app.globalData.playerManager;
    if (playerManager) {
      playerManager.unwatchPlayStatus(this.updatePlayStatus.bind(this));
    }
  },

  // 更新播放状态
  updatePlayStatus(globalData) {
    if (!globalData) return;
    this.setData({
      currentSong: globalData.currentSong,
      isPlaying: globalData.isPlaying
    });
  }
});